<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login Page</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: #f2f2f2;
    }

    .container {
      background-color: #fff;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }

    .container h2 {
      text-align: center;
    }

    .container input {
      width: 100%;
      padding: 10px;
      margin-bottom: 10px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }

    .container button {
      width: 100%;
      padding: 10px;
      background-color: #4CAF50;
      color: #fff;
      border: none;
      border-radius: 3px;
      cursor: pointer;
    }
  </style>
</head>

<body>
  <div class="container">
    <h2>Login</h2>
    <input type="text" id="username" placeholder="Username">
    <input type="password" id="password" placeholder="Password">
    <button id="submit">Login</button>
  </div>
  <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  <script>


    let button = document.querySelector('#submit');
    button.onclick = function () {
      var username = document.getElementById('username').value;
      var password = document.getElementById('password').value;

      // 构建登录请求的数据
      let body = {
        username: username,
        password: password
      };
      $.ajax({
        type: 'post',
        url: 'login',
        contentType: 'application/json; charset=utf8',
        data: JSON.stringify(body),

        success: function (response) {
          if (response.trim() === 'ok') {
            // 登录成功，执行相应操作
            alert('登录成功');
            console.log('Login successful');
            // 重定向到其他页面，或者执行其他操作
          } else {
            // 登录失败，执行相应操作
            console.log('用户名或密码错误');
            // 显示错误信息，或者执行其他操作
            alert('用户名或密码错误');
            location.reload();
          }
        }
      });
    }

  </script>
</body>

</html>